<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/common/common.jsp"%>
<%@ taglib prefix="s" uri="/struts-tags" %> 
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>添加学生</title>
    <link rel="stylesheet" href="./css/layui.css">
</head>
<body>
<!-- 需要设置 form 表单的 enctype 属性为 “multipart/form-data” -->
<form id="form" name="form" class="layui-form" action="<%= basePath%>/StudentAction_add.action" method="post" enctype="multipart/form-data">
    <div class="layui-form-item">
        <label class="layui-form-label">学号</label>
        <div class="layui-input-block">
            <input type="number" name="studentId" id="studentId" required="required"  placeholder="请输入学号" autocomplete="off" class="layui-input"/>
        </div>
    </div>
     <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">人员编号</label>
        <div class="layui-input-block">
            <input type="text" name="personId" id="personId" required="required" placeholder="请输入人员编号" autocomplete="off" class="layui-input" />
        </div>
    </div>
     <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="studentName" id="studentName" required="required" placeholder="请输入姓名" autocomplete="off" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="username" id="username" required="required" placeholder="请输入姓名" autocomplete="off" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="password" name="password" id="password" required="required" placeholder="请输入密码" autocomplete="off" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">专业</label>
        <div class="layui-input-block">
            <input type="text" name="majores" id="majores" required="required" 
            placeholder="请输入专业" autocomplete="off" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">学院</label>
        <div class="layui-input-block">
            <input type="text" name="college" id="college" required="required" placeholder="请输入班级" autocomplete="off" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">班级</label>
        <div class="layui-input-block">
            <input type="text" name="studentClass" id="studentClass" required="required" placeholder="请输入年级" autocomplete="off" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-block">
            <input type="number" name="tel" id="tel" required="required" placeholder="请输入手机号" autocomplete="off" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="email" name="email" id="email" required="required" placeholder="请输入邮箱 " autocomplete="off" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">上传图片</label>
        <input  type="file" name="file" Id="file" onchange="verificationPicFile(this)"/> <br/>
    </div>
     <input type="hidden" name="saveAddress"   value="<%= basePath%>" />

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            <a onclick="javascript:history.back(-1);" class="layui-btn layui-btn-warm"><i class="layui-icon">&#xe65c;</i>返回</a>
        </div>
    </div>
</form>
<script src="./js/jquery.js" type="text/javascript"></script>
<script src="./js/layui.all.js" type="text/javascript"></script>
<script src="./js/alert.js" type="text/javascript"></script>
<script type="text/javascript">

	//图片大小验证
	function verificationPicFile(file) {
	    var fileSize = 0;
	    var fileMaxSize = 10240/1;//图片大小
	    var filePath = file.value;
	    if(filePath){
	        fileSize =file.files[0].size;
	        var size = fileSize / 1024;
	        if (size > fileMaxSize) {
	            Alert("文件大小不能大于100kb！");
	            file.value = "";
	            return false;
	        }else if (size <= 0) {
	            Alert("文件大小不能为0M！");
	            file.value = "";
	            return false;
	        }
	    }else{
	        return false;
	    }
	}
    //Demo
    layui.use(['form'], function(){
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function(data){

        });
        form.render();
    });
</script>

<<%-- script type="text/javascript">
layui.use([ 'form' ], function() {
	var form = layui.form, layer = layui.layer;
	form.on('submit(formDemo)', function(data) {
		//判断不能为空，不会其他了，太拙劣了，重复且量大
		/* if (document.form.studentId.value==""||document.form.studentId.value==null){
		window.alert("请填写学号.")
		return false;
		}else if (document.form.username.value==""||document.form.username.value==null){
		window.alert("请填写项姓名.")
		return false;
		}else if (document.form.password.value==""||document.form.password.value==null){
		window.alert("请填写密码.")
		return false;
		}else if (document.form.major.value==""||document.form.major.value==null){
		window.alert("请填写 专业.")
		return false;
		}else if (document.form.college.value==""||document.form.college.value==null){
		window.alert("请填写学院.")
		return false;
		}else if (document.form.studentClass.value==""||document.form.studentClass.value==null){
		window.alert("请填写班级.")
		return false;
		}else if (document.form.tel.value==""||document.form.tel.value==null){
		window.alert("请填写电话.")
		return false;
		}else if (document.form.email.value==""||document.form.email.value==null){
		window.alert("请填写邮箱.")
		return false;
		} */
	
		var studentId=$("#studentId").val();
		var personId=$("#personId").val();
		var studentName=$("#studentName").val();
		var username=$("#username").val();
		var password=$("#password").val();
		var majores=$("#majores").val();
		var college=$("#college").val();
		var studentClass=$("#studentClass").val();
		var tel=$("#tel").val();
		var email=$("#email").val();
		var file=$("#file").val();
		var saveAddress=$("#saveAddress").val();
		 $.ajax({
			method:'POST',
			url:'<%= basePath%>/StudentAction_add.action',
			 data:{studentId:studentId,personId:personId,studentName:studentName,username:username,password:password,majores:majores,college:college,studentClass:studentClass,
			tel:tel,email:email,file:file,saveAddress:saveAddress},
			//data: $("#form").serialize(),
			//判断从后台传值过来的data数据
			success:function(data){
				alert("添加成功！");
				console.log("添加成功了")
				//点击确定按钮后执行list动作
				window.location.href="<%= basePath%>/StudentAction_list.action"
			}
		});
		return false;
	});  --%>
	<%-- $.post('<%= basePath%>/StudentAction_add.action',$("#form").serialize(),function(){
		console.log("成功了")
	}) 
 
});

</script>--%>

</body>
</html>